<script type="text/javascript">
// 输入框选择
function onButtonEdit(btnEdit,url) {
    mini.open({
        url: url,
        title: "选择列表",
        width: 750,
        height: 380,
        ondestroy: function (action) {
            if (action == "ok") {
                var iframe = this.getIFrameEl();
                var data = iframe.contentWindow.GetData();
                data = mini.clone(data);
                if (data) {
                    btnEdit.setValue(data.id);
                    btnEdit.setText(data.name);
                }
            }
        }
    });
    $(".mini-panel-border .mini-panel-body iframe").css("height","98%");
}

// 编辑记录模版
function onActionRenderer(e) {
    var grid = e.sender;
    var record = e.record;
    var uid = record._uid;
    var rowIndex = e.rowIndex;

    var s = ' <a class="RowButton" href="javascript:editRow(\'' + uid + '\')">编辑</a>'
          + ' <a class="RowButton" href="javascript:delRow(\'' + uid + '\')">删除</a>';

    if (grid.isEditingRow(record)) {
        s = ' <a class="RowButton" href="javascript:updateRow(\'' + uid + '\')"> 提交 </a>'
          + ' <a class="RowButton" href="javascript:cancelRow(\'' + uid + '\')"> 取消 </a>'
    }
    return s;
}

/*
//编辑记录模版
function onEdit(e) {
    var grid = e.sender;
    var record = e.record;
    var uid = record._uid;
    var rowIndex = e.rowIndex;

    var s = ' <a class="RowButton" href="javascript:editRow(\'' + uid + '\')">编辑</a>'

    if (grid.isEditingRow(record)) {
        s = ' <a class="RowButton" href="javascript:updateRow(\'' + uid + '\')"> 提交 </a>'
          + ' <a class="RowButton" href="javascript:cancelRow(\'' + uid + '\')"> 取消 </a>'
    }
    return s;
}
*/

// 编辑记录
function editRow(row_uid) {
    var row = grid.getRowByUID(row_uid);
    if (row) {
        grid.cancelEdit();
        grid.beginEditRow(row);
    }
}

// 新增记录
function newRow() {            
    var row = {};
    grid.addRow(row, 0);

    grid.cancelEdit();
    grid.beginEditRow(row);
}

// 取消修改
function cancelRow(row_uid) {            
    grid.reload();
}

// 删除数据
function delRow(row_uid) {
    var row = grid.getRowByUID(row_uid);
    if (row) {
    	parent.$.dooDialog.confirm("你确定要删除吗？",function(){
            grid.loading("删除中，请稍后......");
            $.ajax({
            	type:"POST",
                url:urlDel,
                data:{id:row.id},
                cache:false,
                success:function(text){
                    grid.reload();
                },
                error:function(){}
            });
        });
    }
}

// 提交修改的记录
function updateRow(row_uid) {
    var row = grid.getRowByUID(row_uid);

    grid.commitEdit();
    var rowData = grid.getChanges();
    
    grid.loading("保存中，请稍后......");
    $.ajax({
    	type:"POST",
        url:urlUpd,
        data:{data:rowData[0]},
        cache:false,
        success:function(text){
        	//mini.get("buttonAdd").disable();
            grid.reload();
        },
        error:function(){}
	});
}

// excel导出
function ExportExcel() {
    var columns = grid.getBottomColumns();
    
    function getColumns(columns) {
        columns = columns.clone();
        for (var i = columns.length - 1; i >= 0; i--) {
            var column = columns[i];
            if (!column.field) {
                columns.removeAt(i);
            } else {
                var c = { header: column.header, field: column.field };
                columns[i] = c;
            }
        }
        return columns;
    }
    
    var columns = getColumns(columns);
    var json = mini.encode(columns);

    var url = "export.aspx?type=excel&columns=" + encodeURI(json);
    var exportIFrame = document.getElementById("exportIFrame");
    exportIFrame.src = url;

}

// 顾客详情
function CustomerInfo(name){
	var row = grid.getSelected();
	if (row != null) {
		mini.open({
            url: "/common/customerInfo?id=" + row[name],
            title: "顾客详情", width: 500, height: 250
        });
		$(".mini-panel-border .mini-panel-body iframe").css("height","95%");
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
}

// 工单详情
function BusinessInfo(name){
	var row = grid.getSelected();
	if (row != null) {
		mini.open({
            url: "/common/businessInfo?id=" + row[name],
            title: "顾客详情", width: 1000, height: 450
        });
		$(".mini-panel-border .mini-panel-body iframe").css("height","95%");
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
}

//工单详情
function BusinessInfo2(name){
	var row = grid.getSelected();
	if (row != null) {
		mini.open({
            url: "/common/businessInfo2?id=" + row[name],
            title: "顾客详情", width: 1000, height: 450
        });
		$(".mini-panel-border .mini-panel-body iframe").css("height","95%");
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
}

//隐藏加载条
parent.$('#StartLoad').hide();
</script>
</body>
</html>
</body>
</html>